package models

import (
	"yunion.io/x/onecloud/pkg/apis"
	api "yunion.io/x/onecloud/pkg/apis/llm"
)

var sharedApiWorkerEnvKeyVal []*apis.ContainerKeyValue

func getSharedApiWorkerEnv(custom *DifyContainerEnv) []*apis.ContainerKeyValue {
	if sharedApiWorkerEnvKeyVal == nil {
		sharedApiWorkerEnv := &DifyContainerEnv{
			"CONSOLE_API_URL":                                  "",
			"CONSOLE_WEB_URL":                                  "",
			"SERVICE_API_URL":                                  "",
			"APP_API_URL":                                      "",
			"APP_WEB_URL":                                      "",
			"LANG":                                             "en_US.UTF-8",
			"LC_ALL":                                           "en_US.UTF-8",
			"PYTHONIOENCODING":                                 "utf-8",
			"LOG_LEVEL":                                        "INFO",
			"LOG_FILE":                                         "/app/logs/server.log",
			"LOG_FILE_MAX_SIZE":                                "20",
			"LOG_FILE_BACKUP_COUNT":                            "5",
			"LOG_DATEFORMAT":                                   "%Y-%m-%d %H:%M:%S",
			"LOG_TZ":                                           "UTC",
			"DEBUG":                                            "false",
			"FLASK_DEBUG":                                      "false",
			"ENABLE_REQUEST_LOGGING":                           "False",
			"SECRET_KEY":                                       api.DIFY_SECRET_KEY,
			"INIT_PASSWORD":                                    "",
			"DEPLOY_ENV":                                       "PRODUCTION",
			"CHECK_UPDATE_URL":                                 "https://updates.dify.ai",
			"OPENAI_API_BASE":                                  "https://api.openai.com/v1",
			"MIGRATION_ENABLED":                                "true",
			"FILES_ACCESS_TIMEOUT":                             "300",
			"ACCESS_TOKEN_EXPIRE_MINUTES":                      "60",
			"REFRESH_TOKEN_EXPIRE_DAYS":                        "30",
			"APP_MAX_ACTIVE_REQUESTS":                          "0",
			"APP_MAX_EXECUTION_TIME":                           "1200",
			"DIFY_BIND_ADDRESS":                                "0.0.0.0",
			"DIFY_PORT":                                        "5001",
			"SERVER_WORKER_AMOUNT":                             "1",
			"SERVER_WORKER_CLASS":                              "gevent",
			"SERVER_WORKER_CONNECTIONS":                        "10",
			"CELERY_WORKER_CLASS":                              "",
			"GUNICORN_TIMEOUT":                                 "360",
			"CELERY_WORKER_AMOUNT":                             "",
			"CELERY_AUTO_SCALE":                                "false",
			"CELERY_MAX_WORKERS":                               "",
			"CELERY_MIN_WORKERS":                               "",
			"API_TOOL_DEFAULT_CONNECT_TIMEOUT":                 "10",
			"API_TOOL_DEFAULT_READ_TIMEOUT":                    "60",
			"ENABLE_WEBSITE_JINAREADER":                        api.DIFY_WEB_ENABLE_WEBSITE_JINAREADER,
			"ENABLE_WEBSITE_FIRECRAWL":                         api.DIFY_WEB_ENABLE_WEBSITE_FIRECRAWL,
			"ENABLE_WEBSITE_WATERCRAWL":                        api.DIFY_WEB_ENABLE_WEBSITE_WATERCRAWL,
			"DB_USERNAME":                                      api.DIFY_POSTGRES_USER,
			"DB_PASSWORD":                                      api.DIFY_POSTGRES_PASSWORD,
			"DB_HOST":                                          api.DIFY_LOCALHOST,
			"DB_PORT":                                          api.DIFY_POSTGRES_PORT,
			"DB_DATABASE":                                      "dify",
			"SQLALCHEMY_POOL_SIZE":                             "30",
			"SQLALCHEMY_POOL_RECYCLE":                          "3600",
			"SQLALCHEMY_ECHO":                                  "false",
			"SQLALCHEMY_POOL_PRE_PING":                         "false",
			"SQLALCHEMY_POOL_USE_LIFO":                         "false",
			"POSTGRES_MAX_CONNECTIONS":                         api.DIFY_POSTGRES_MAX_CONNECTIONS,
			"POSTGRES_SHARED_BUFFERS":                          api.DIFY_POSTGRES_SHARED_BUFFERS,
			"POSTGRES_WORK_MEM":                                api.DIFY_POSTGRES_WORK_MEM,
			"POSTGRES_MAINTENANCE_WORK_MEM":                    api.DIFY_POSTGRES_MAINTENANCE_WORK_MEM,
			"POSTGRES_EFFECTIVE_CACHE_SIZE":                    api.DIFY_POSTGRES_EFFECTIVE_CACHE_SIZE,
			"REDIS_HOST":                                       api.DIFY_LOCALHOST,
			"REDIS_PORT":                                       api.DIFY_REDIS_PORT,
			"REDIS_USERNAME":                                   "",
			"REDIS_PASSWORD":                                   api.DIFY_REDISCLI_AUTH,
			"REDIS_USE_SSL":                                    "false",
			"REDIS_DB":                                         "0",
			"REDIS_USE_SENTINEL":                               "false",
			"REDIS_SENTINELS":                                  "",
			"REDIS_SENTINEL_SERVICE_NAME":                      "",
			"REDIS_SENTINEL_USERNAME":                          "",
			"REDIS_SENTINEL_PASSWORD":                          "",
			"REDIS_SENTINEL_SOCKET_TIMEOUT":                    "0.1",
			"REDIS_USE_CLUSTERS":                               "false",
			"REDIS_CLUSTERS":                                   "",
			"REDIS_CLUSTERS_PASSWORD":                          "",
			"CELERY_BROKER_URL":                                "redis://:" + api.DIFY_REDISCLI_AUTH + "@" + api.DIFY_LOCALHOST + ":" + api.DIFY_REDIS_PORT + "/1",
			"CELERY_BACKEND":                                   api.DIFY_LOCALHOST,
			"BROKER_USE_SSL":                                   "false",
			"CELERY_USE_SENTINEL":                              "false",
			"CELERY_SENTINEL_MASTER_NAME":                      "",
			"CELERY_SENTINEL_PASSWORD":                         "",
			"CELERY_SENTINEL_SOCKET_TIMEOUT":                   "0.1",
			"STORAGE_TYPE":                                     "opendal",
			"OPENDAL_SCHEME":                                   "fs",
			"OPENDAL_FS_ROOT":                                  "storage",
			"VECTOR_STORE":                                     "weaviate",
			"VECTOR_INDEX_NAME_PREFIX":                         "Vector_index",
			"WEAVIATE_ENDPOINT":                                "http://" + api.DIFY_LOCALHOST + ":8080",
			"WEAVIATE_API_KEY":                                 api.DIFY_WEAVIATE_AUTHENTICATION_APIKEY_ALLOWED_KEYS,
			"UPLOAD_FILE_SIZE_LIMIT":                           "15",
			"UPLOAD_FILE_BATCH_LIMIT":                          "5",
			"ETL_TYPE":                                         "dify",
			"UNSTRUCTURED_API_URL":                             "",
			"UNSTRUCTURED_API_KEY":                             "",
			"SCARF_NO_ANALYTICS":                               "true",
			"PROMPT_GENERATION_MAX_TOKENS":                     "512",
			"CODE_GENERATION_MAX_TOKENS":                       "1024",
			"PLUGIN_BASED_TOKEN_COUNTING_ENABLED":              "false",
			"MULTIMODAL_SEND_FORMAT":                           "base64",
			"UPLOAD_IMAGE_FILE_SIZE_LIMIT":                     "10",
			"UPLOAD_VIDEO_FILE_SIZE_LIMIT":                     "100",
			"UPLOAD_AUDIO_FILE_SIZE_LIMIT":                     "50",
			"API_SENTRY_DSN":                                   api.DIFY_API_SENTRY_DSN,
			"API_SENTRY_TRACES_SAMPLE_RATE":                    api.DIFY_API_SENTRY_TRACES_SAMPLE_RATE,
			"API_SENTRY_PROFILES_SAMPLE_RATE":                  api.DIFY_API_SENTRY_PROFILES_SAMPLE_RATE,
			"WEB_SENTRY_DSN":                                   "",
			"NOTION_INTEGRATION_TYPE":                          "public",
			"NOTION_CLIENT_SECRET":                             "",
			"NOTION_CLIENT_ID":                                 "",
			"NOTION_INTERNAL_SECRET":                           "",
			"MAIL_TYPE":                                        "resend",
			"MAIL_DEFAULT_SEND_FROM":                           "",
			"RESEND_API_URL":                                   "https://api.resend.com",
			"RESEND_API_KEY":                                   "your-resend-api-key",
			"SMTP_SERVER":                                      "",
			"SMTP_PORT":                                        "465",
			"SMTP_USERNAME":                                    "",
			"SMTP_PASSWORD":                                    "",
			"SMTP_USE_TLS":                                     "true",
			"SMTP_OPPORTUNISTIC_TLS":                           "false",
			"SENDGRID_API_KEY":                                 "",
			"INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH":          api.DIFY_WEB_INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH,
			"INVITE_EXPIRY_HOURS":                              "72",
			"RESET_PASSWORD_TOKEN_EXPIRY_MINUTES":              "5",
			"CHANGE_EMAIL_TOKEN_EXPIRY_MINUTES":                "5",
			"OWNER_TRANSFER_TOKEN_EXPIRY_MINUTES":              "5",
			"CODE_EXECUTION_ENDPOINT":                          "http://" + api.DIFY_LOCALHOST + ":8194",
			"CODE_EXECUTION_API_KEY":                           api.DIFY_SANDBOX_API_KEY,
			"CODE_MAX_NUMBER":                                  "9223372036854775807",
			"CODE_MIN_NUMBER":                                  "-9223372036854775808",
			"CODE_MAX_DEPTH":                                   "5",
			"CODE_MAX_PRECISION":                               "20",
			"CODE_MAX_STRING_LENGTH":                           "80000",
			"CODE_MAX_STRING_ARRAY_LENGTH":                     "30",
			"CODE_MAX_OBJECT_ARRAY_LENGTH":                     "30",
			"CODE_MAX_NUMBER_ARRAY_LENGTH":                     "1000",
			"CODE_EXECUTION_CONNECT_TIMEOUT":                   "10",
			"CODE_EXECUTION_READ_TIMEOUT":                      "60",
			"CODE_EXECUTION_WRITE_TIMEOUT":                     "10",
			"TEMPLATE_TRANSFORM_MAX_LENGTH":                    "80000",
			"WORKFLOW_MAX_EXECUTION_STEPS":                     "500",
			"WORKFLOW_MAX_EXECUTION_TIME":                      "1200",
			"WORKFLOW_CALL_MAX_DEPTH":                          "5",
			"MAX_VARIABLE_SIZE":                                "204800",
			"WORKFLOW_PARALLEL_DEPTH_LIMIT":                    "3",
			"WORKFLOW_FILE_UPLOAD_LIMIT":                       "10",
			"WORKFLOW_NODE_EXECUTION_STORAGE":                  "rdbms",
			"CORE_WORKFLOW_EXECUTION_REPOSITORY":               "core.repositories.sqlalchemy_workflow_execution_repository.SQLAlchemyWorkflowExecutionRepository",
			"CORE_WORKFLOW_NODE_EXECUTION_REPOSITORY":          "core.repositories.sqlalchemy_workflow_node_execution_repository.SQLAlchemyWorkflowNodeExecutionRepository",
			"API_WORKFLOW_NODE_EXECUTION_REPOSITORY":           "repositories.sqlalchemy_api_workflow_node_execution_repository.DifyAPISQLAlchemyWorkflowNodeExecutionRepository",
			"API_WORKFLOW_RUN_REPOSITORY":                      "repositories.sqlalchemy_api_workflow_run_repository.DifyAPISQLAlchemyWorkflowRunRepository",
			"HTTP_REQUEST_NODE_MAX_BINARY_SIZE":                "10485760",
			"HTTP_REQUEST_NODE_MAX_TEXT_SIZE":                  "1048576",
			"HTTP_REQUEST_NODE_SSL_VERIFY":                     "True",
			"RESPECT_XFORWARD_HEADERS_ENABLED":                 "false",
			"SSRF_PROXY_HTTP_URL":                              "http://" + api.DIFY_LOCALHOST + ":3128",
			"SSRF_PROXY_HTTPS_URL":                             "http://" + api.DIFY_LOCALHOST + ":3128",
			"LOOP_NODE_MAX_COUNT":                              api.DIFY_WEB_LOOP_NODE_MAX_COUNT,
			"MAX_TOOLS_NUM":                                    api.DIFY_WEB_MAX_TOOLS_NUM,
			"MAX_PARALLEL_LIMIT":                               api.DIFY_WEB_MAX_PARALLEL_LIMIT,
			"MAX_ITERATIONS_NUM":                               api.DIFY_WEB_MAX_ITERATIONS_NUM,
			"TEXT_GENERATION_TIMEOUT_MS":                       api.DIFY_WEB_TEXT_GENERATION_TIMEOUT_MS,
			"ALLOW_UNSAFE_DATA_SCHEME":                         api.DIFY_WEB_ALLOW_UNSAFE_DATA_SCHEME,
			"POSTGRES_USER":                                    "${DB_USERNAME}",
			"POSTGRES_PASSWORD":                                "${DB_PASSWORD}",
			"POSTGRES_DB":                                      "${DB_DATABASE}",
			"PGDATA":                                           "/var/lib/postgresql/data/pgdata",
			"SANDBOX_API_KEY":                                  api.DIFY_SANDBOX_API_KEY,
			"SANDBOX_GIN_MODE":                                 api.DIFY_SANDBOX_GIN_MODE,
			"SANDBOX_WORKER_TIMEOUT":                           api.DIFY_SANDBOX_WORKER_TIMEOUT,
			"SANDBOX_ENABLE_NETWORK":                           api.DIFY_SANDBOX_ENABLE_NETWORK,
			"SANDBOX_HTTP_PROXY":                               api.DIFY_SANDBOX_HTTP_PROXY,
			"SANDBOX_HTTPS_PROXY":                              api.DIFY_SANDBOX_HTTPS_PROXY,
			"SANDBOX_PORT":                                     api.DIFY_SANDBOX_PORT,
			"WEAVIATE_PERSISTENCE_DATA_PATH":                   api.DIFY_WEAVIATE_PERSISTENCE_DATA_PATH,
			"WEAVIATE_QUERY_DEFAULTS_LIMIT":                    api.DIFY_WEAVIATE_QUERY_DEFAULTS_LIMIT,
			"WEAVIATE_AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED": api.DIFY_WEAVIATE_AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED,
			"WEAVIATE_DEFAULT_VECTORIZER_MODULE":               api.DIFY_WEAVIATE_DEFAULT_VECTORIZER_MODULE,
			"WEAVIATE_CLUSTER_HOSTNAME":                        api.DIFY_WEAVIATE_CLUSTER_HOSTNAME,
			"WEAVIATE_AUTHENTICATION_APIKEY_ENABLED":           api.DIFY_WEAVIATE_AUTHENTICATION_APIKEY_ENABLED,
			"WEAVIATE_AUTHENTICATION_APIKEY_ALLOWED_KEYS":      api.DIFY_WEAVIATE_AUTHENTICATION_APIKEY_ALLOWED_KEYS,
			"WEAVIATE_AUTHENTICATION_APIKEY_USERS":             api.DIFY_WEAVIATE_AUTHENTICATION_APIKEY_USERS,
			"WEAVIATE_AUTHORIZATION_ADMINLIST_ENABLED":         api.DIFY_WEAVIATE_AUTHORIZATION_ADMINLIST_ENABLED,
			"WEAVIATE_AUTHORIZATION_ADMINLIST_USERS":           api.DIFY_WEAVIATE_AUTHORIZATION_ADMINLIST_USERS,
			"NGINX_SERVER_NAME":                                api.DIFY_NGINX_SERVER_NAME,
			"NGINX_PORT":                                       api.DIFY_NGINX_PORT,
			"NGINX_WORKER_PROCESSES":                           api.DIFY_NGINX_WORKER_PROCESSES,
			"NGINX_CLIENT_MAX_BODY_SIZE":                       api.DIFY_NGINX_CLIENT_MAX_BODY_SIZE,
			"NGINX_KEEPALIVE_TIMEOUT":                          api.DIFY_NGINX_KEEPALIVE_TIMEOUT,
			"NGINX_PROXY_READ_TIMEOUT":                         api.DIFY_NGINX_PROXY_READ_TIMEOUT,
			"NGINX_PROXY_SEND_TIMEOUT":                         api.DIFY_NGINX_PROXY_SEND_TIMEOUT,
			"SSRF_HTTP_PORT":                                   api.DIFY_SSRF_HTTP_PORT,
			"SSRF_COREDUMP_DIR":                                api.DIFY_SSRF_COREDUMP_DIR,
			"SSRF_REVERSE_PROXY_PORT":                          api.DIFY_SANDBOX_PORT,
			"SSRF_SANDBOX_HOST":                                api.DIFY_LOCALHOST,
			"SSRF_DEFAULT_TIME_OUT":                            "5",
			"SSRF_DEFAULT_CONNECT_TIME_OUT":                    "5",
			"SSRF_DEFAULT_READ_TIME_OUT":                       "5",
			"SSRF_DEFAULT_WRITE_TIME_OUT":                      "5",
			"DB_PLUGIN_DATABASE":                               api.DIFY_PLUGIN_DB_DATABASE,
			"PLUGIN_DAEMON_PORT":                               api.DIFY_PLUGIN_SERVER_PORT,
			"PLUGIN_DAEMON_KEY":                                api.DIFY_PLUGIN_SERVER_KEY,
			"PLUGIN_DAEMON_URL":                                "http://" + api.DIFY_LOCALHOST + ":" + api.DIFY_PLUGIN_SERVER_PORT,
			"PLUGIN_MAX_PACKAGE_SIZE":                          api.DIFY_PLUGIN_MAX_PACKAGE_SIZE,
			"PLUGIN_PPROF_ENABLED":                             api.DIFY_PLUGIN_PPROF_ENABLED,
			"PLUGIN_DEBUGGING_HOST":                            api.DIFY_PLUGIN_REMOTE_INSTALLING_HOST,
			"PLUGIN_DEBUGGING_PORT":                            api.DIFY_PLUGIN_REMOTE_INSTALLING_PORT,
			"EXPOSE_PLUGIN_DEBUGGING_HOST":                     api.DIFY_LOCALHOST,
			"EXPOSE_PLUGIN_DEBUGGING_PORT":                     api.DIFY_PLUGIN_REMOTE_INSTALLING_PORT,
			"PLUGIN_DIFY_INNER_API_KEY":                        api.DIFY_API_INNER_KEY,
			"PLUGIN_DIFY_INNER_API_URL":                        "http://" + api.DIFY_LOCALHOST + ":5001",
			"ENDPOINT_URL_TEMPLATE":                            "http://" + api.DIFY_LOCALHOST + "/e/{hook_id}",
			"MARKETPLACE_ENABLED":                              "true",
			"MARKETPLACE_API_URL":                              api.DIFY_WEB_MARKETPLACE_API_URL,
			"ALLOW_EMBED":                                      api.DIFY_WEB_ALLOW_EMBED,
			"QUEUE_MONITOR_THRESHOLD":                          "200",
			"QUEUE_MONITOR_ALERT_EMAILS":                       "",
			"QUEUE_MONITOR_INTERVAL":                           "30",
			"ENABLE_CLEAN_EMBEDDING_CACHE_TASK":                "false",
			"ENABLE_CLEAN_UNUSED_DATASETS_TASK":                "false",
			"ENABLE_CREATE_TIDB_SERVERLESS_TASK":               "false",
			"ENABLE_UPDATE_TIDB_SERVERLESS_STATUS_TASK":        "false",
			"ENABLE_CLEAN_MESSAGES":                            "false",
			"ENABLE_MAIL_CLEAN_DOCUMENT_NOTIFY_TASK":           "false",
			"ENABLE_DATASETS_QUEUE_MONITOR":                    "false",
			"ENABLE_CHECK_UPGRADABLE_PLUGIN_TASK":              "true",
		}
		sharedApiWorkerEnvKeyVal = sharedApiWorkerEnv.GetContainerEnvs(custom)
	}
	return sharedApiWorkerEnvKeyVal
}
